<?php
require_once "../model/connectdb.php";
require_once "../model/spider.class.php";
error_reporting(0);
$db=new db();
$db->connectdb();
$relativeUrlListA=$db->select("SELECT * FROM relativeUrl WHERE type=0");
$db->close();//获得各类相关链接的地址列表
foreach ($relativeUrlListA as $row) {
	$id=$row['id'];
	$catName=$row['cat'];
	$relativeUrlList=json_decode(urldecode($row['relativeUrl']),1);
	//print_r($relativeUrlList);
	$spider=new cwantSpider();
	$contentAll=$spider->getContent($relativeUrlList);//所有链接整理出来的文章内容结果
	//$content=$spider->getAllContent($relativeUrlList);
	$db=new db();
	$db->connectdb();
	foreach ($contentAll as $key=>$row) {
		$lead_image_url=$row['content']['lead_image_url'];
		$title=$row['content']['title'];
		$content=$row['content']['content'];
		$url=$row['url'];
		echo $title." ".$url."<br/>";
		$res=$db->query("INSERT INTO contents (lead_image_url,title,content,cat,url) VALUES ('$lead_image_url','$title','$content','$catName','$url')");
		if(!$res){
			mysql_error();
		}
	}
	$db->close();
	$db=new db();
	$db->connectdb();
	$db->query("UPDATE relativeUrl SET type=1 WHERE id='$id'");
	$db->close();
	
}?>